/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.impl;

import dao.AccountDao;
import entity.Pet;
import entity.PetOwner;
import entity.PetOwner;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.logging.Level;
import java.util.logging.Logger;
import until.BaseDAO;

/**
 *
 * @author Administrator
 */
public class AccountMYSQLImpl extends BaseDAO implements AccountDao {
    @Override
    public int updateSell(Pet pet, int ownerId, int storeId) {
        int state = 0;

        try {
            Connection con;
            con = BaseDAO.getConnection();
            PreparedStatement pst = con.prepareStatement("INSERT INTO account (DEAL_TYPE,PET_ID,SELLER_ID,BUYER_ID,PRICE,DEAL_TIME)VALUE(?,?,?,?,?,?)");
            pst.setInt(1, 2);
            pst.setInt(2, pet.getId());
            pst.setInt(3, ownerId);
            pst.setInt(4, storeId);
            pst.setInt(5, pet.getPrice());
            pst.setDate(6, null);
            state = pst.executeUpdate();
            BaseDAO.closeConnection(con);
        } catch (SQLException ex) {
            Logger.getLogger(PetMYSQLImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        return state;
    }

    @Override
    public int update(Pet pet, PetOwner po) {
        int state = 0;
        Date date = Date.valueOf(LocalDate.MAX);
        try {
            Connection con;
            con = BaseDAO.getConnection();
            PreparedStatement pst = con.prepareStatement("INSERT INTO account (DEAL_TYPE,PET_ID,SELLER_ID,BUYER_ID,PRICE,DEAL_TIME)VALUE(?,?,?,?,?,?)");
            pst.setInt(1, 1);
            pst.setInt(2, pet.getId());
            pst.setInt(3, pet.getStore_id());
            pst.setInt(4, po.getId());
            pst.setInt(5, pet.getPrice());
            pst.setDate(6, null);
            state = pst.executeUpdate();
            BaseDAO.closeConnection(con);
        } catch (SQLException ex) {
            Logger.getLogger(PetMYSQLImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        return state;
    }

}
